﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrderList.aspx.cs" Inherits="famails.BackEnd.Customer.OrderList" MasterPageFile="~/Master.Master" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="width: 100%; padding: 10px;">
        <!--start content 01-->
        <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="border: 1px solid #333; margin-bottom: 10px; padding: 0px;">
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding: 10px 20px; background: #000; color: #fff; font-size: 18px; font-weight: bold; position: relative;">
                Danh sách đơn hàng
            </div>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:0px">
            <asp:Panel Visible="false" ID="pnError" runat="server">
                <div class="error-box round col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                    <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
                </div>
            </asp:Panel>
            <asp:Panel Visible="false" ID="pnSuccess" runat="server">
                <div class="confirmation-box round col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                    <asp:Label ID="lblSuccess" runat="server" Text=""></asp:Label>
                </div>
            </asp:Panel>
            </div>
            <style>
                #contentjqxgrid {
                    width: 100% !important;
                }

                #pagerjqxgrid {
                    width: 100% !important;
                }

                #columntablejqxgrid {
                    width: 100% !important;
                }

                .jqx-grid-header {
                    width: 100% !important;
                }
            </style>
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                <asp:Panel ID="Panel1" runat="server">
                    <fieldset style="padding: 5px 0px;" id="pnSearch">
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="padding: 5px; padding-left: 0px;margin-bottom:25px;">
                            <span for="simple-input" style="padding: 5px 10px;border: 1px solid #333;font-weight: bolder; font-size: 18px; text-transform: none"><span style="margin-right:5px;" class="fa fa-search"></span> Tìm kiếm đơn hàng</span>
                        </div>
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="padding: 0px;">
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Mã đơn hàng</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <asp:TextBox runat="server" CssClass="form-control" Style="border-radius: 0px; border: 1px solid #333;" ID="txtOrderCode"></asp:TextBox></div>
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Mã giao hàng</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <asp:TextBox runat="server" CssClass="form-control" Style="border-radius: 0px; border: 1px solid #333;" ID="txtDeliveryCode"></asp:TextBox>
                            </div>
                        </div>
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="padding: 0px;">
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Theo tên</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <asp:TextBox runat="server" CssClass="form-control" Style="border-radius: 0px; border: 1px solid #333;" ID="txtName"></asp:TextBox></div>
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Nhóm khách hàng</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <asp:DropDownList ID="ddlGroup" runat="server" Style="border-radius: 0px; border: 1px solid #333;" CssClass="form-control"></asp:DropDownList>
                            </div>
                        </div>
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="padding: 0px;">
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Theo điện thoại</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <asp:TextBox runat="server" CssClass="form-control" Style="border-radius: 0px; border: 1px solid #333;" ID="txtPhone"></asp:TextBox></div>
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Theo email</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <asp:TextBox runat="server" CssClass="form-control" Style="border-radius: 0px; border: 1px solid #333;" ID="txtEmail"></asp:TextBox></div>
                        </div>
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12" style="padding: 0px;">
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Từ ngày</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;height:40px;">
                                <div id="txtFromDate"></div>
                            </div>
                            <div class="col-md-2 col-lg-2 col-sm-3 col-xs-6" style="padding: 5px; line-height: 30px;">Đến ngày</div>
                            <div class="col-md-4 col-lg-4 col-sm-3 col-xs-6" style="padding: 5px;">
                                <div id="txtToDate"></div>
                            </div>
                        </div>
                        <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 pull-right" style="padding: 0px;">
                            <div id="btnSearch" style="float: left;  background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px; border: 1px solid #fff;" class="btn col-xs-6 col-lg-2 col-sm-3 col-md-2">
                                <span class="fa fa-desktop" style="margin-right: 10px;"></span>Lọc dữ liệu 
                            </div>
                            <div id="btnExportExcel" style="float: left; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px; border: 1px solid #fff;" class="btn col-xs-6 col-lg-2 col-sm-3 col-md-2">
                                <span class="fa fa-mail-forward" style="margin-right: 10px;"></span>Xuất dữ liệu 
                            </div>
                            <a href="orders.aspx" style="float: left; margin-right: 10px; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px; border: 1px solid #fff;" class="btn col-xs-12 col-lg-2 col-sm-3 col-md-3"><span class="fa fa-plus" style="margin-right: 10px;"></span>Thêm mới đơn hàng</a>
                            
                        </div>

                    </fieldset>
                </asp:Panel>
            </div>
            <div class="col-sm-12 col-xs-12 col-md-12 col-lg-12 " style="padding: 0px;">
                <div id='jqxWidget' style="width: 100% !important; font-size: 13px; font-family: Verdana; float: left;">
                    <div id="jqxgrid" style="width: 100% !important;"></div>
                </div>

                <div id="popupWindow">
                    <div>
                        Xóa đơn hàng
                    </div>
                    <div style="overflow: hidden;">
                        <p>
                            Bạn có chắc là muốn xóa đơn hàng này không?
                        </p>
                        <button id="del">
                            Yes</button>
                        <button id="cancel">
                            No</button>
                    </div>
                </div>
            </div>



        </div>


    </div>
    <script type="text/javascript">
        jQuery(function ($) {
            $("#txtFromDate").jqxDateTimeInput({ width: '120px', height: '25px' });
            $("#txtToDate").jqxDateTimeInput({ width: '120px', height: '25px' });
            $("#btnExportExcel").click(function () {
                $("#jqxgrid").jqxGrid('exportdata', 'xls', 'orderlist');
            });

            $("#btnSearch").click(function () {
                var url = "OrderList.aspx/Search";
                $("#jqxgrid").jqxGrid('showloadelement');
                var postValue = "{ordercode:'" + $('#ContentPlaceHolder1_txtOrderCode').val() + "',deliverycode:'" + $('#ContentPlaceHolder1_txtDeliveryCode').val() + "',name:'" + $('#ContentPlaceHolder1_txtName').val() + "',phone:'" + $('#ContentPlaceHolder1_txtPhone').val() + "',email:'" + $('#ContentPlaceHolder1_txtEmail').val() + "',from:'" + $('#txtFromDate').val() + "',to:'" + $('#txtToDate').val() + "',groupid:" + $('#ContentPlaceHolder1_ddlGroup').val() + "}";
                //alert(postValue);
                $.ajax({
                    type: "POST",
                    url: url,
                    data: postValue,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'OrderID', type: 'int' },
                        { name: 'CustomerName', type: 'string' },
                        { name: 'DeliveryCode', type: 'string' },
                        { name: 'OrderCode', type: 'string' },
                        { name: 'Amount', type: 'decimal' },
                        { name: 'Deposit', type: 'decimal' },
                        { name: 'DeliveryFee', type: 'decimal' },
                        { name: 'RealAmount', type: 'decimal' },
                        { name: 'OrderDate', type: 'date' },
                          { name: 'DeliveryDate', type: 'date' },
                          { name: 'Status', type: 'string' },
                          { name: 'Payment', type: 'string' },
                          { name: 'Delivery', type: 'string' }
                    ],
                    id: 'OrderID',
                    localdata: data,
                    pager: function (pagenum, pagesize, oldpagenum) {
                    }
                };
                        var dataAdapter = new $.jqx.dataAdapter(source);
                        $("#jqxgrid").jqxGrid(
                        {
                            width: $('#jqxWidget').width(),
                            source: dataAdapter,
                            selectionmode: 'multiplerowsextended',
                            sortable: true,
                            pageable: true,
                            autoheight: true,
                            columnsresize: true,
                            columns: [
                              { text: 'Họ tên', datafield: 'CustomerName',width:150},
                              { text: 'Giá trị', datafield: 'Amount', width: 120, cellsformat: 'number', cellsalign: 'right' },
                              { text: 'Tiền cọc', datafield: 'Deposit', cellsformat: 'number', width: 100, cellsalign: 'right' },
                              //{ text: 'Phí giao hàng', datafield: 'DeliveryFee', cellsformat: 'number', width: 100, cellsalign: 'right' },
                              { text: 'Phải thu', datafield: 'RealAmount', cellsformat: 'number', width: 120, cellsalign: 'right' },
                              { text: 'Mã giao hàng', datafield: 'DeliveryCode' }, { text: 'Mã đơn hàng', datafield: 'OrderCode' },
                              //{ text: 'Ngày đặt hàng', datafield: 'OrderDate',  cellsformat: 'dd/MM/yyyy', cellsalign: 'center' },
                              //{ text: 'Ngày giao hàng', datafield: 'DeliveryDate',  cellsformat: 'dd/MM/yyyy', cellsalign: 'center' },
                              { text: 'Trang thái', datafield: 'Status' },
                              //{ text: 'Hình thức TT', datafield: 'Payment' },
                              {
                                  text: 'Xem đơn hàng', columntype: 'button', width: 120, cellsalign: 'center', cellsrenderer: function () {
                                      return "Xem";
                                      //return '<input type="image" style="margin-left: 5px;" height="30" width="30" src="../resource/images/delete-icon.png"/>';
                                  }, buttonclick: function (row) {
                                      editrowindex = row;
                                      var id = $("#jqxgrid").jqxGrid('getcellvalue', row, "OrderID");
                                      window.open('OrderPrint.aspx?Id=' + id, "_blank");
                                  }
                              },
                              {
                                  text: 'Chỉnh sửa', datafield: 'Edit', columntype: 'button', cellsrenderer: function () {
                                      return "Chỉnh sửa";
                                      //return '<input type="image" style="margin-left: 5px;" height="30" width="30" src="../resource/images/delete-icon.png"/>';
                                  }, buttonclick: function (row) {
                                      editrowindex = row;
                                      var id = $("#jqxgrid").jqxGrid('getcellvalue', row, "OrderID");
                                      window.location = 'Orders.aspx?Id=' + id;
                                  }
                              },
                               {
                                   text: 'Xóa', datafield: 'Delete', columntype: 'button', width: 50, cellsrenderer: function () {
                                       return "Xóa";
                                   }, buttonclick: function (row) {
                                       // open the popup window when the user clicks a button.
                                       id = $("#jqxgrid").jqxGrid('getrowid', row);
                                       var offset = $("#jqxgrid").offset();
                                       $("#popupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
                                       // show the popup window.
                                       $("#popupWindow").jqxWindow('show');
                                   }
                               }]
                        });

                    }
                });
            });
            $("#popupWindow").jqxWindow({ width: 250, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.01 });
            $("#del").jqxButton({ theme: theme });
            $("#cancel").jqxButton({ theme: theme });
            $("#del").click(function () {
                $.ajax({
                    type: "POST",
                    url: "OrderList.aspx/Delete",
                    data: "{id:" + id + "}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $('#jqxgrid').jqxGrid('deleterow', id);
                        $("#popupWindow").jqxWindow('hide');
                    }
                });
            });
            $("#cancel").click(function () {
                $("#popupWindow").jqxWindow('hide');
            });
            $('#btnSearch').trigger('click');
        });
    </script>
</asp:Content>

